# redis/redis_operations.py

from .redis_client import get_redis_client

def set_key(key: str, value: str, expire_time: int = None):
    """设置键值对"""
    client = get_redis_client()
    client.set(key, value)
    if expire_time:
        client.expire(key, expire_time)

def get_key(key: str):
    """获取键对应的值"""
    client = get_redis_client()
    value = client.get(key)
    if isinstance(value, bytes):
        return value.decode('utf-8')
    return value

def delete_key(key: str):
    """删除键"""
    client = get_redis_client()
    client.delete(key)

def check_key_exists(key: str):
    """检查键是否存在"""
    client = get_redis_client()
    return client.exists(key)
